package cn.breeze.product.controller;

import cn.breeze.product.service.IProductOnlineAuditLogService;
import cn.breeze.product.domain.ProductOnlineAuditLog;
import cn.breeze.product.query.ProductOnlineAuditLogQuery;
import cn.breeze.basic.utils.AjaxResult;
import cn.breeze.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.breeze.basic.exception.BusinessException;
import cn.breeze.basic.annotation.PreAuthorize;

import java.util.List;

@RestController
@RequestMapping("/productOnlineAuditLog")
public class ProductOnlineAuditLogController {
    @Autowired
    private  IProductOnlineAuditLogService productOnlineAuditLogService;


    /**
     * 保存和修改公用的
     * @param productOnlineAuditLog  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    @PreAuthorize(name = "保存productOnlineAuditLog", sn = "productOnlineAuditLog:save")
    public AjaxResult addOrUpdate(@RequestBody ProductOnlineAuditLog productOnlineAuditLog){
        try {
            if( productOnlineAuditLog.getId()!=null)
                productOnlineAuditLogService.update(productOnlineAuditLog);
            else
                productOnlineAuditLogService.save(productOnlineAuditLog);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    @PreAuthorize(name = "删除productOnlineAuditLog", sn = "productOnlineAuditLog:delete")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            productOnlineAuditLogService.remove(id);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试1");
        }
    }
	
    //获取用户
    @GetMapping("/{id}")
    @PreAuthorize(name = "获取productOnlineAuditLog", sn = "productOnlineAuditLog:get")
    public ProductOnlineAuditLog get(@PathVariable("id")Long id)
    {
        return productOnlineAuditLogService.loadById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    @PreAuthorize(name = "获取所有productOnlineAuditLog", sn = "productOnlineAuditLog:loadAll")
    public List<ProductOnlineAuditLog> list(){

        return productOnlineAuditLogService.loadAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    @PreAuthorize(name = "列表productOnlineAuditLog", sn = "productOnlineAuditLog:list")
    public PageList<ProductOnlineAuditLog> queryData(@RequestBody ProductOnlineAuditLogQuery query)
    {
        return productOnlineAuditLogService.queryData(query);
    }

    /**
    * @Title: patchRemove
    * @Description: 批量删除
    * @Author: Mr.D
    * @Version: 1.0
    * @Date:  2022/7/18 16:57
    * @Parameters: [ids]
    * @Return cn.breeze.basic.utils.AjaxResult
    */
    @PatchMapping
    @PreAuthorize(name = "批量删除productOnlineAuditLog", sn = "productOnlineAuditLog:patchDelete")
    public AjaxResult patchRemove(@RequestBody Long[] ids){
        try {
            productOnlineAuditLogService.patchRemove(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试试！");
        }
    }
}
